## Figure A1: Clustering of Closing Dates by Hour and City

## install.packages(c("tidyverse"))
## library(tidyverse)

## SET WORKING DIRECTORY HERE
## setwd()

## Loading data
## load("dta.RData")

clustering_hour= dta %>%
  filter(close_hour != "NA:00") %>%
  mutate(n = 1,
         close_hour = factor(close_hour, levels = c("0:00", "1:00", "2:00", "3:00",
                                                    "4:00", "5:00", "6:00", "7:00",
                                                    "8:00", "9:00", "10:00", "11:00",
                                                    "12:00", "13:00", "14:00", "15:00",
                                                    "16:00", "17:00", "18:00",
                                                    "19:00", "20:00", "21:00",
                                                    "22:00", "23:00", "24:00"))) %>%
  group_by(city, close_hour) %>%
  summarise(n_requests_closed = sum(n, na.rm = TRUE)) %>%
  ggplot(aes(x = factor(close_hour), y = n_requests_closed)) +
  facet_wrap(city ~ ., scales = "free", ncol = 2) +
  geom_bar(stat = "identity", color="black", fill="gray") +
  scale_x_discrete(labels = c("", "", "", "", "", "", "6:00", "",
                              "", "", "", "", "12:00", "", "", "",
                              "", "", "18:00", "", "", "", "", "",
                              "24:00")) +
  labs(x = "Hour",
       y = "# of Requests Closed") +
  theme_classic()+
  theme(panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank(),
        panel.background = element_rect(colour = "black"))